package com.thxy.jxgl.bumen.manager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.thxy.jxgl.db.DB;
import com.thxy.jxgl.javaBean.BuMen;
import com.thxy.jxgl.javaBean.GangWei;
import com.thxy.jxgl.javaBean.User;
import com.thxy.jxgl.javaBean.khbz;
import com.thxy.jxgl.javaBean.khinfo;
import com.thxy.jxgl.javaBean.khjsff;
import com.thxy.jxgl.javaBean.khmbz;
import com.thxy.jxgl.javaBean.khxm;
import com.thxy.jxgl.javaBean.khzb;



public class GangweiManager {

	private static GangweiManager instance = new GangweiManager();
	
	private GangweiManager(){}
	
	public static GangweiManager getInstance(){
		return instance;
	}
	
	public List getGangwei(){
		List gwlist = new ArrayList();
		Connection conn = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		String sql = "select * from t_gangwei";		
		try {
			conn = DB.getConn();
			pstm = conn.prepareStatement(sql);
			rs = pstm.executeQuery();
			while (rs.next()) {
				GangWei gw=new GangWei();
				gw.setGw_id(rs.getString("gw_id"));
				gw.setGw_name(rs.getString("gw_name"));
				gwlist.add(gw);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{			
			DB.close(rs);			
			DB.close(pstm);
			DB.close(conn);
		}
		return gwlist;		
	}
	public boolean addGangwei(String gwno,String gwname){
		Connection conn=null;
		PreparedStatement pstm=null;
		String sql="INSERT INTO t_gangwei (gw_id,gw_name) VALUES(?,?)";
		try {
			conn = DB.getConn();
			pstm = conn.prepareStatement(sql);
			pstm.setString(1, gwno);
			pstm.setString(2, gwname);
			return pstm.execute();	
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}finally{				
			DB.close(pstm);
			DB.close(conn);
		}
	}
	public boolean deleGangwei(String gwno){
		Connection conn=null;
		PreparedStatement pstm=null;
		String sql="DELETE FROM t_gangwei WHERE gw_id=?";
		try {
			conn = DB.getConn();
			pstm = conn.prepareStatement(sql);
			pstm.setString(1, gwno);
			return pstm.execute();	
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}finally{				
			DB.close(pstm);
			DB.close(conn);
		}
	}
	
	
		
}
